package com.hqyj.springboot_project01.test.service.impl;

import com.hqyj.springboot_project01.common.entity.Result;
import com.hqyj.springboot_project01.test.dao.CityDao;
import com.hqyj.springboot_project01.test.entity.City;
import com.hqyj.springboot_project01.test.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class CityServiceImpl implements CityService {
    @Autowired
    private CityDao cityDao;

    @Override
    @Transactional
    public Result<City> insertCity(City city) {
        city.setDateCreated(new Date());
        cityDao.insertCity(city);
        return new Result<>(Result.ResultCode.SUCCESS.code,
                "Insert success", city);
    }

    @Override
    @Transactional
    public Result<City> updateCity(City city) {
        cityDao.updateCity(city);
        return new Result<>(Result.ResultCode.SUCCESS.code,
                "Update success", city);
    }

    @Override
    @Transactional
    public Result<Object> deleteCityById(int cityId) {
        cityDao.deleteCityById(cityId);
        return new Result<>(Result.ResultCode.SUCCESS.code,
                "Delete success", cityId);
    }

    @Override
    @Transactional
    public City getCityById(int cityId) {
        return cityDao.getCityById(cityId);
    }


}
